//
//  NewHomeTableViewCell.m
//  SunXi
//
//  Created by dllo on 15/12/4.
//  Copyright © 2015年 大远. All rights reserved.
//

#import "NewHomeTableViewCell.h"

@implementation NewHomeTableViewCell{
    UIImageView *_userimageView;
    UILabel *_messlabel;
    UILabel *_Newlabel;
    UILabel *_username;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createData];
    }
    return self;
}
- (void)createData{
    _userimageView = [[UIImageView alloc]init];
    [SCV addSubview:_userimageView];
    
    _username = [[UILabel alloc]init];
    [SCV addSubview:_username];
    
    _messlabel = [[UILabel alloc]init];
    [SCV addSubview:_messlabel];
    
    _Newlabel = [[UILabel alloc]init];
    [SCV addSubview:_Newlabel];
    
    
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [_userimageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(35, 35));
        make.top.equalTo(SCV).offset(5);
        make.left.equalTo(SCV).offset(20);
    }];
    _userimageView.image = [UIImage imageNamed:@"haoyou"];
    
    [_username mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_userimageView);
        make.left.equalTo(_userimageView.mas_right).offset(5);
        make.size.mas_equalTo(CGSizeMake(200, 20));
        
    }];
    _username.text = self.usermodel.user;
    [_messlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_userimageView.mas_bottom).offset(10);
        make.left.equalTo(_userimageView);
        make.right.equalTo(_Newlabel.mas_left);
        make.bottom.equalTo(SCV);
    }];
    _messlabel.numberOfLines = 0;
    
    if ([self.usermodel.mess hasPrefix:@"SXmovie:"]) {
        NSString *str = [self.usermodel.mess stringByReplacingOccurrencesOfString:@"SXmovie:" withString:@"分享:"];
        NSArray *strArr = [str componentsSeparatedByString:@"网址"];
        _messlabel.text = [strArr firstObject];
    }else if ([self.usermodel.mess hasPrefix:@"SXlook:"]) {
        NSString *str = [self.usermodel.mess stringByReplacingOccurrencesOfString:@"SXlook:" withString:@"分享:"];
        NSArray *strArr = [str componentsSeparatedByString:@"网址"];
        _messlabel.text = [strArr firstObject];
    }else if ([self.usermodel.mess hasPrefix:@"SXradio:"]) {
        NSString *str = [self.usermodel.mess stringByReplacingOccurrencesOfString:@"SXradio:" withString:@"分享:"];
        NSArray *strArr = [str componentsSeparatedByString:@"网址"];
        _messlabel.text = [strArr firstObject];
    }else{
        _messlabel.text = self.usermodel.mess;
        
    }
    
    
    [_Newlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(SCV);
        make.right.equalTo(SCV).offset(-20);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    _Newlabel.BC = [UIColor redColor];
    _Newlabel.textAlignment = NSTextAlignmentCenter;
    _Newlabel.textColor = [UIColor whiteColor];
    _Newlabel.layer.cornerRadius = 15;
    _Newlabel.layer.masksToBounds  = YES;
    ;
    if ([self.number isEqualToNumber:@0]) {
        _Newlabel.hidden = YES;
    }else{
        _Newlabel.hidden = NO;
        _Newlabel.text = [NSString stringWithFormat:@"%@",self.number];
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
